﻿#pragma once

#include "Render/Shader.h"
#include "Render/VertexArray.h"
#include "Render/CubeMap.h"

class CORE_API Skybox
{
public:
  Skybox();

  float GetTimeSpeed() const { return m_timeSpeed; }
  float GetRotation() const;

  void SetTimeSpeed(float speed) { m_timeSpeed = speed; }
  void SetTime(float time);
  float GetTimeOfDay() { return m_time / m_dayLength; }; 
  float GetDayLength() { return m_dayLength; }

  glm::vec4 GetSkyColorByTime();
  glm::vec4 GetSunshineColorByTime();
  glm::vec3 GetSunshineDirection();

  float GetTime() const { return m_time; }
  float GetDayLength() const { return m_dayLength; }

  void Update(const glm::mat4 &projection, const glm::mat4 &view, float deltaTime);
  void Render();

private:
  glm::mat4 m_transform{1};
  VertexArray m_vertexArray{
      std::vector<glm::vec3>{
          {1, 1, 1},
          {1, 1, -1},
          {1, -1, 1},
          {1, -1, -1},
          {-1, 1, 1},
          {-1, 1, -1},
          {-1, -1, 1},
          {-1, -1, -1},
      },
      std::vector<VertexAttribute>{{3, VertexAttribute::Float}},
      std::vector<uint8_t>{0, 1, 5, 4, 0, 5, 2, 1, 0, 1, 2, 3, 7, 4, 5, 4, 7, 6,
                           1, 3, 7, 1, 7, 5, 4, 6, 0, 2, 0, 6, 3, 2, 6, 7, 3, 6},
  };
  Ref<CubeMap> m_cubeMap;
  Ref<Shader> m_shader;

  float m_time = 55.f;
  float m_timeSpeed = 1.f;
  const float m_dayLength = 60.f * 10;
};